﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

using Microsoft.Practices.Composite.Presentation.Commands;
using Scoreboard.Model;
using Scoreboard.Interfaces;
using System.Collections.Generic;
using Scoreboard.Data;
using Scoreboard.Basement;
using Scoreboard.Basement.ViewModels;

namespace Scoreboard.TournamentManagement
{
	public class AddTournamentDialogViewModel : DialogViewModel
	{
		private ITournamentRepository _repository;

		private string _name;
		private bool _isForDoubles;		

		public AddTournamentDialogViewModel(ITournamentRepository repository)
		{
			_repository = repository;

			AddTournamentCommand = new DelegateCommand<object>(AddTournamentCommandHandler);

			HasCloseButton = true;
			InitialTitle = "Создать турнир";

			InitialCommands.Add(new UserCommand("Добавить", AddTournamentCommand));
			InitialCommands.Add(new UserCommand("Отмена", CloseWindowCommand));			
		}

		public string Name
		{
			get
			{
				return _name;
			}
			set
			{
				_name = value;
				FirePropertyChanged("Name");
			}
		}

		public bool IsForDoubles
		{
			get
			{
				return _isForDoubles;
			}
			set
			{
				_isForDoubles = value;
				FirePropertyChanged("IsForDoubles");
			}
		}		

		public ICommand AddTournamentCommand { get; private set; }

		private void AddTournamentCommandHandler(object parameter)
		{
			var tournament = new Tournament
			{
				Name = this.Name,
				IsForDoubles = this.IsForDoubles
			};
			_repository.AddTournament(tournament);

			CloseWindow();
		}		
	}
}
